#include <iostream>
#include <vector>

using namespace std;

vector<int> num;

bool check(int i)
{
    while(i)
    {
        if(--num[i%10]<0){return false;}
        i /= 10;
    }
    return true;
}

int main()
{
	int n;
	cin>>n;
	num = vector<int>(10,n);
	
    int i=1;
    while(check(i)) i++; 
    
    cout<<--i;
    return 0;
}
